<?php
namespace Application\Form;

use Zend\Form\Fieldset;
use Zend\InputFilter\InputFilterProviderInterface;

class ProfileFieldset extends Fieldset implements InputFilterProviderInterface
{
    public function init()
    {
        $em = $this->getFormFactory()->getFormElementManager()->getServiceLocator()->get('doctrine.entitymanager.orm_default');
        $this->setHydrator(new \DoctrineModule\Stdlib\Hydrator\DoctrineObject($em, 'Application\Model\Entity\Utilisateur'));
        
        $this->add(array(
            'type' => 'text',
            'name' => 'nom',
            'options' => array('label' => 'Nom :'),
            'attributes' => array(
                'class' => 'form-control',
            ),
        ));
        
        $this->add(array(
            'type' => 'text',
            'name' => 'prenom',
            'options' => array('label' => 'Prénom :'),
            'attributes' => array(
                'class' => 'form-control',
            ),
        ));
        
        $this->add(array(
            'type' => 'submit',
            'name' => 'submit',
            'options' => array('label' => 'Enregister les modifications'),
            'attributes' => array('class' => 'btn btn-success'),
        ));
    }

    public function getInputFilterSpecification()
    {
        return array(
            'nom' => array(
                'required' => true,
                'validators' => array(
                    array(
                        'name' => 'NotEmpty',
                        'break_chain_on_failure' => true,
                        'options' => array(
                            'messages' => array(
                                'isEmpty' => 'Ce champ est obligatoire',
                            ),
                        ),
                    ),
                ),
            ),
            'prenom' => array(
                'required' => true,
                'validators' => array(
                    array(
                        'name' => 'NotEmpty',
                        'break_chain_on_failure' => true,
                        'options' => array(
                            'messages' => array(
                                'isEmpty' => 'Ce champ est obligatoire',
                            ),
                        ),
                    ),
                ),
            ),
        );
    }
}
